home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gnat1792.zip
/
gnat179b
/
t-adainc
/
a-stwiun.adb
< prev
next >
Wrap
Text File
|
1994-05-19
|
17KB
|
574 lines
------------------------------------------------------------------------------
-- --
-- GNAT RUNTIME COMPONENTS --
-- --
-- A D A . S T R I N G S . W I D E _ U N B O U N D E D --
-- --
-- B o d y --
-- --
-- $Revision: 1.3 $ --
-- --
-- Copyright (c) 1992,1993,1994 NYU, All Rights Reserved --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. --
-- --
------------------------------------------------------------------------------
-- Note: This code is derived from the ADAR.CSH public domain Ada 83
-- version of Strings.Bounded of the Appendix C string handling packages.
with Ada.Strings.Wide_Fixed;
with Ada.Strings.Wide_Search;
with Unchecked_Deallocation;
package body Ada.Strings.Wide_Unbounded is
-----------------------
-- Local Subprograms --
-----------------------
procedure Free (Handle : in out Unbounded_Wide_String);
-- Free an unbounded string using unchecked deallocation. This is used
-- only internally to this package by those routines which must be sure
-- to free a string before reassigning it. This is a temporary kludge
-- to make up for the fact that we do not have finalization yet! ???
---------
-- "=" --
---------
function "=" (Left, Right : in Unbounded_Wide_String) return Boolean is
begin
return Left.Reference.all = Right.Reference.all;
end "=";
---------
-- "<" --
---------
function "<" (Left, Right : in Unbounded_Wide_String) return Boolean is
begin
return Left.Reference.all < Right.Reference.all;
end "<";
----------
-- "<=" --
----------
function "<=" (Left, Right : in Unbounded_Wide_String) return Boolean is
begin
return Left.Reference.all <= Right.Reference.all;
end "<=";
---------
-- ">" --
---------
function ">" (Left, Right : in Unbounded_Wide_String) return Boolean is
begin
return Left.Reference.all > Right.Reference.all;
end ">";
----------
-- ">=" --
----------
function ">=" (Left, Right : in Unbounded_Wide_String) return Boolean is
begin
return Left.Reference.all >= Right.Reference.all;
end ">=";
---------
-- "*" --
---------
function "*" (Left : in Natural; Right : in Wide_Character)
return Unbounded_Wide_String
is
Result : Unbounded_Wide_String :=
(Reference => new Wide_String (1 .. Left));
begin
Result.Reference.all := (1 .. Left => Right);
return Result;
end "*";
function "*" (Left : in Natural; Right : in Wide_String)
return Unbounded_Wide_String
is
Result : Unbounded_Wide_String :=
(Reference => new Wide_String (1 .. Left * Right'Length));
begin
for I in 1 .. Left loop
Result.Reference.all
(Right'Length * I - Right'Length + 1 .. Right'Length * I) := Right;
end loop;
return Result;
end "*";
function "*" (Left : in Natural; Right : in Unbounded_Wide_String)
return Unbounded_Wide_String
is
R_Length : constant Integer := Right.Reference.all'Length;
Result : Unbounded_Wide_String :=
(Reference =>
new Wide_String (1 .. Left * Right.Reference.all'Length));
begin
for I in 1 .. Left loop
Result.Reference.all (R_Length * I - R_Length + 1 .. R_Length * I) :=
Right.Reference.all;
end loop;
return Result;
end "*";
---------
-- "&" --
---------
function "&" (Left, Right : in Unbounded_Wide_String)
return Unbounded_Wide_String
is
L_Length : constant Integer := Left.Reference.all'Length;
R_Length : constant Integer := Right.Reference.all'Length;
Length : constant Integer := L_Length + R_Length;
Result : Unbounded_Wide_String :=
(Reference => new Wide_String (1 .. Length));
begin
Result.Reference.all (1 .. L_Length) := Left.Reference.all;
Result.Reference.all (L_Length + 1 .. Length) := Right.Reference.all;
return Result;
end "&";
function "&" (Left : in Unbounded_Wide_String; Right : Wide_String)
return Unbounded_Wide_String
is
L_Length : constant Integer := Left.Reference.all'Length;
Length : constant Integer := L_Length + Right'Length;
Result : Unbounded_Wide_String :=
(Reference => new Wide_String (1 .. Length));
begin
Result.Reference.all (1 .. L_Length) := Left.Reference.all;
Result.Reference.all (L_Length + 1 .. Length) := Right;
return Result;
end "&";
function "&" (Left : in Wide_String; Right : Unbounded_Wide_String)
return Unbounded_Wide_String
is
R_Length : constant Integer := Right.Reference.all'Length;
Length : constant Integer := Left'Length + R_Length;
Result : Unbounded_Wide_String :=
(Reference => new Wide_String (1 .. Length));
begin
Result.Reference.all (1 .. Left'Length) := Left;
Result.Reference.all (Left'Length + 1 .. Length) := Right.Reference.all;
return Result;
end "&";
function "&" (Left : in Unbounded_Wide_String; Right : Wide_Character)
return Unbounded_Wide_String
is
Length : constant Integer := Left.Reference.all'Length + 1;
Result : Unbounded_Wide_String :=
(Reference => new Wide_String (1 .. Length));
begin
Result.Reference.all (1 .. Length - 1) := Left.Reference.all;
Result.Reference.all (Length) := Right;
return Result;
end "&";
function "&" (Left : in Wide_Character; Right : Unbounded_Wide_String)
return Unbounded_Wide_String
is
Length : constant Integer := Right.Reference.all'Length + 1;
Result : Unbounded_Wide_String :=
(Reference => new Wide_String (1 .. Length));
begin
Result.Reference.all (1) := Left;
Result.Reference.all (2 .. Length) := Right.Reference.all;
return Result;
end "&";
-----------
-- Count --
-----------
function Count (Source : in Unbounded_Wide_String;
Pattern : in Wide_String;
Mapping : in Wide_Maps.Wide_Character_Mapping
:= Wide_Maps.Identity)
return Natural is
begin
return Wide_Search.Count (Source.Reference.all, Pattern, Mapping);
end Count;
function Count (Source : in Unbounded_Wide_String;
Pattern : in Wide_String;
Mapping : in Wide_Maps.Wide_Character_Mapping_Function)
return Natural is
begin
return Wide_Search.Count (Source.Reference.all, Pattern, Mapping);
end Count;
function Count (Source : in Unbounded_Wide_String;
Set : in Wide_Maps.Wide_Character_Set)
return Natural is
begin
return